package com.example.intelligentattendancesystem.mapping;

import com.example.intelligentattendancesystem.pojo.History;
import com.example.intelligentattendancesystem.pojo.Late;
import com.example.intelligentattendancesystem.pojo.Leave;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LeaveMapping {
    /**
     * 新增用户请假记录
     *
     * @param leave 打卡记录
     * @return 修改的条数
     */
    @Insert("insert into t_leave values(#{id}, #{userId}, #{leaveStartTime},#{leaveEndTime},#{access},#{date})")
    int insertLeave(Leave leave);

    /**
     * 通过ID查询用户的请假记录
     *
     * @param userId
     * @return
     */
    @Select("select id,user_id as userId , leave_start_time as leaveStartTime , leave_end_time as leaveEndTime, access,date " +
            "from t_leave where user_id = #{userId} " +
            "order by leave_start_time" )
    List<Leave> selectLeaveByUserId(int userId);

    /**
     * 通过账号删除用户的请假记录
     *
     * @param userId
     * @return 修改的条数
     */
    @Delete("delete from t_leave where user_id = #{userId}")
    int deleteLeaveByUserId(int userId);


    /**
     * 查询所有用户的所有请假记录
     *
     * @return 请假记录
     */
    @Select("select id,user_id as userId , leave_start_time as leaveStartTime , leave_end_time as leaveEndTime, access,date from t_leave" +
            " order by leave_start_time")
    List<Leave> selectAllLeave();

    /**
     * 更新通过状态
     * @param leave
     * @return
     */
    @Update("update t_leave set access = #{access} where leave_start_time = #{leaveStartTime} and user_id = #{userId}")
    int updateLeave(Leave leave);
}
